/*
 * Program finds two neighbouring numbers in an array with the smallest distance to each other. 
 * The index of the first number is outputted to the screen.
 */
import java.util.*;
public class ArraysNeighboringNumbers{
	public static void main(String[] args){
		// Inintialize input from keyboard
		Scanner in = new Scanner(System.in);
		// Initialize Array where numbers will be input from keyboard
		int[] MyArray;
		MyArray = new int[1];
		int i = 0;
	
		// Input numbers into array
		System.out.println("Input some numbers");
		while (in.hasNextInt()){ 
			System.out.println("i="+i);
			MyArray = Arrays.copyOf(MyArray, i+1);
			MyArray[i]=in.nextInt();
			System.out.println("MyArray[i]="+MyArray[i]);
			System.out.println(in.hasNextInt());
			i++;		
		}
	
		// Set minimum range and index to first pair
		int minimumRange= Math.abs(MyArray[1]-MyArray[0]);
		int minimumIndex = 0;
		
		// Search for minimum range and index
		for (i = 1; i < MyArray.length; i++){
			if (minimumRange > Math.abs(MyArray[i]-MyArray[i-1])){
				minimumRange = Math.abs(MyArray[i]-MyArray[i-1]);
				minimumIndex = i-1;
			}
		}
		
		// Print index of first number with minimum range.
		System.out.println("index for minimum range is " + minimumIndex);
	}	
}